from typing import Callable

from aiogram.fsm.state import State
from aiogram_dialog import Window
from aiogram_dialog.api.internal import Widget
from aiogram_dialog.widgets.kbd import Cancel, ScrollingGroup, Select
from aiogram_dialog.widgets.text import Format
from aiogram_dialog.widgets.utils import GetterVariant

from poker_bot.tg_bot.dialogs.widgets import LocaleText


def get_list_window(
    main_text: str,
    items_text: str,
    items_getter: str,
    state: State,
    getter: GetterVariant,
    handler: Callable,
    additional_widgets: list[Widget] | None = None,
) -> Window:
    if additional_widgets is None:
        additional_widgets = []
    return Window(
        LocaleText(
            main_text,
        ),
        ScrollingGroup(
            Select(
                Format(items_text),
                "items_sel",
                lambda item: item.id,
                items_getter,
                on_click=handler,
            ),
            width=1,
            height=4,
            id="useritemssel",
            hide_on_single_page=True,
        ),
        *additional_widgets,
        Cancel(
            LocaleText("back-btn"),
        ),
        state=state,
        getter=getter,
    )
